﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ConceptCorporateAdmin.Gui;

namespace ConceptCorporateAdmin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            TvLista.RefreshLista();
            Console.WriteLine(Program.AppPath);
        }

        

        private void BtnAdaugaCategorie_Click(object sender, EventArgs e)
        {
            if (TvLista.SelectedExNode != null)
            {
                if (TvLista.SelectedExNode.TipNod == TipuriNoduri.Categorie)
                {
                    String nume = InputBox.ShowMe("Numele categoriei:");
                    if (!nume.Trim().Equals(""))
                        TvLista.AddCategorie(nume);
                }
                else
                {
                    MessageBox.Show("Va rugam alegeti o categorie!");
                }
            }
            else
            {
                MessageBox.Show("Va rugam alegeti o categorie!");
            }
        }

        private void BtnSterge_Click(object sender, EventArgs e)
        {
            TvLista.RemoveSelectedNode();
        }

        private void BtnAdaugaActNormativ_Click(object sender, EventArgs e)
        {
            if (TvLista.SelectedExNode != null)
            {
                if (TvLista.SelectedExNode.TipNod == TipuriNoduri.Categorie)
                {
                    int id_categorie  = ((DbCategorie)TvLista.SelectedExNode.InnerObject).Id;
                    DbActNormativ act = Gui.Dialogs.ActNormativ.ShowNew(id_categorie);
                    if (act != null)
                    {
                        ExTreeNode nod = new ExTreeNode(act.Nume, TipuriNoduri.ActeNormative, act);
                        TvLista.SelectedExNode.Nodes.Add(nod);
                    }
                }
            }
        }

        private void TvLista_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (TvLista.SelectedExNode != null)
            {
                if (TvLista.SelectedExNode.TipNod == TipuriNoduri.ActeNormative)
                {
                    //actNormativView1.ActNormativ = (DbActNormativ)TvLista.SelectedExNode.InnerObject;
                }
            }
        }

        private void TvLista_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if( TvLista.SelectedExNode != null && TvLista.SelectedExNode.TipNod == TipuriNoduri.ActeNormative)
                    MeniuActNormativ.Show( TvLista, e.X, e.Y);
            }
        }

        private void editeazaActToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (TvLista.SelectedExNode != null)
            {
                if (TvLista.SelectedExNode.TipNod == TipuriNoduri.ActeNormative)
                {
                    DbActNormativ act = (DbActNormativ)TvLista.SelectedExNode.InnerObject;
                    int id_act       = act.Id;
                    int id_cat       = act.IdCategorie;
                    act              = Gui.Dialogs.ActNormativ.ShowEdit(id_cat, id_act);
                    if (act != null)
                    {
                        TvLista.SelectedExNode.InnerObject = act;
                        TvLista.SelectedExNode.Text = act.Nume;
                    }
                }
            }
        }

        private void actNormativView1_Load(object sender, EventArgs e)
        {

        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
           
            //Browser.Document.Body.SetAttribute("contenteditable", "true");
          // Browser.Document.exe
            // NameService.setDocument(Browser.Document);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Browser.Navigate("http://www.google.com/search?client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&channel=s&hl=en&q=woot&btnG=Google+Search");
        }

        private void BtnGenerate_Click(object sender, EventArgs e)
        {
            LstEntitati.generateTreeFromString(DocumentEditor.DocumentText);
        }   

    }
}
